/**
 * Created by luqidong on 2017/12/14.
 */
import {h5tonativeclose, postcall, parseDom, h5toh5htmlclose} from '../uitls/common';
import wxjswap from '../uitls/wxjswap2';
import store from 'store2';
export const paytypefn = ({Code, data, senddata})=> {
    return new Promise((resolve, reject)=> {
        switch (Code) {
            case 'XTCZ':
                const {LotteryID, ChaseCount}=senddata;
                resolve('success');
                if(ChaseCount && ChaseCount > 1) {
                    //TODO 本地跳转
                }
                else {
                    if([1, 2, 11, 12].indexOf(parseInt(LotteryID)) > -1) {
                        //TODO 本地跳转
                    }
                    else {
                        //TODO 本地跳转
                    }
                }
                return;
                break;
            case 'XXP_ZFB':
                if(!isiOS(navigator.userAgent)) {
                    try {
                        //TDbridge.PluginPay.sendurl({url: data.data});
                        //{"title":"咨询药师","pageType":"1","url":"/api/index.html","jumpType":"1","params":{"token":"232342342342343","branchId":"32423424234"}}
                        let senddata = {
                            title: '支付结果',
                            pageType: 2006,
                            jumpType: 2,
                            url: data.data
                        };
                        TDbridge.skipApp.startSkipApp(senddata)
                    }
                    catch (e) {
                        h5tonativeclose('充值中间页', data.data);
                    }
                }
                else {
                    h5tonativeclose('充值中间页', data.data);
                }
                return;
                break;
            case 'XXP_WX':
            case'XY_WX':
                h5tonativeclose('充值中间页', data.data);
                return;
                break;
            case 'YLO_QQ': //优络QQ支付
            case 'YLO_WX': //优络QQ支付
                TDbridge.appPlugin.startAppPlugin({
                    'type': 25,
                    ULOParams: {
                        ...data.data, ...{
                            rightUrl: 'http://www.baidu.com',
                            errorUrl: 'http://taobao.com'
                        }
                    }
                });
                break;
            case 'OY_WX':
            case 'OY_ZFB':
                postcall(data.data.action, (data.data));
                return;
                break;
            case 'WFT_QQ':
            case 'WFT_ZFB':
            case 'WFT_WX':
                try {
                    const {token_id, services}=data.data;
                    TDbridge.PluginPay.weifutongPay({
                        token_id,
                        trade_type: services,
                        paynumber: data.msg
                    });
                }
                catch (e) {

                }
                return;
                break;
            case 'NOW_WX':
            case 'NOW_ZFB':
                const tpf = parseDom(data.data);
                document.body.appendChild(tpf);
                document.querySelector('form').submit();
                document.body.removeChild(tpf);
                break;
            case 'WFT_WX_WAP':
                h5tonativeclose('充值中间页', data.data.pay_info);
                break;
            case 'HW_PAY':
                TDbridge.PluginPay.huaweipay({
                    ...data.data
                });
                break;
            case 'HY_WX':
                const url = wxjswap(data.data);
                store('payMiddleRedirect', {
                    url,
                    returnUrl: `${location.origin}/#/security/payresult`
                });
                h5tonativeclose('支付中间页', `/security/paymiddlepage`, ()=> {
                    window.location.href = url;
                });
                break;
            case 'ZYF_WX':
            case 'ZYF_ZFB':
                h5toh5htmlclose('支付中间页', payCode, data.data);
                break;
            case 'HY_ZFB':
                store('payMiddleRedirect', {
                    url: `alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=${data.data}`,
                    returnUrl: `${location.origin}/#/security/payresult`
                });
                h5tonativeclose('支付中间页', `/security/paymiddlepage`);
                break;
        }
    });

};